//
// Created by 谢哲 on 2021/4/18.
//

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

class Person {
public:
    string name;
    int bg = 0, dj = 0, zw = 0, px=0;

    Person() = default;
    Person(string name, int zw, int bg, int dj, int px): name(name), zw(zw), bg(bg), dj(dj), px(px) {}
};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    vector<string> zhiwei_dict = {"BangZhu", "FuBangZhu", "HuFa", "ZhangLao", "TangZhu", "JingYing", "BangZhong"};
    vector<int> zhiwei_remain = {0, 0, 2, 4, 7, 25, 200};

    int n;
    cin>>n;

    vector<Person> vdata;

    for(int i=0;i<n;++i) {
        string name, zw_str;
        int bg, dj;
        cin>>name>>zw_str>>bg>>dj;

        int zw = 0;
        for (int j=0;j<7;++j) {
            if (zw_str==zhiwei_dict[j]) {
                zw = j;
                break;
            }
        }

        vdata.emplace_back(Person(name, zw, bg, dj, i));
    }

    // bg sort
    sort(vdata.begin(), vdata.end(), [](const Person &a, const Person &b){return a.bg > b.bg || (a.bg==b.bg&&a.zw<b.zw);});

    int current_zw = 2;

    for (auto &p: vdata) {
        if (p.zw<2) continue;

        p.zw = current_zw;
        --zhiwei_remain[current_zw];
        if (zhiwei_remain[current_zw]<=0) {
            ++current_zw;
        }
    }

    // zw, dj sort
    sort(vdata.begin(), vdata.end(), [](const Person &a, const Person &b) {
       return a.zw<b.zw||(a.zw==b.zw&&a.dj>b.dj)||(a.zw==b.zw&&a.dj==b.dj&&a.px<b.px);
    });

    for (const auto &p: vdata) {
        cout<<p.name<<" "<<zhiwei_dict[p.zw]<<" "<<p.dj<<"\n";
    }

    return 0;
}
